<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon
      @click="toggleClick"
      :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
    />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data () {
    return {
      isFullscreen: false
    }
  },
  created () {
    //   检测全屏状态改变 screenfull.on 监听
    screenfull.on('change', () => {
      console.log(screenfull.isFullscreen)
      //   screenfull.isFullscreen拿到当前全屏状态
      // 进入true,没有进入false
      this.isFullscreen = screenfull.isFullscreen
    })
  },
  methods: {
    toggleClick () {
      screenfull.toggle()
      //   setTimeout(() => {
      this.isFullscreen = !this.isFullscreen
      //   }, 500)
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
